# coding:utf-8
from spf.account.models import *
from django import forms
from django.db import models
from django.forms.util import ErrorList


class CashAccountForm(forms.ModelForm):
    """
    the form of user info
    """

    def __init__(self, user, *args, **kwargs):
        self.owner = user
        super(CashAccountForm, self).__init__( *args, **kwargs)

    def save(self, commit=True):
        acct = super(CashAccountForm, self).save(commit=False)
        acct.owner = self.owner
        if commit:
            acct.save()
        return acct 
        

    class Meta:
        model = CashAccount
        fields = ("name", "currency", "balance")
        #excludes = ("user")

class FixedForm(forms.ModelForm):
    """
    the form of user info
    """

    def __init__(self, user, *args, **kwargs):
        self.owner = user
        super(FixedForm, self).__init__( *args, **kwargs)

    def save(self, commit=True):
        acct = super(FixedForm, self).save(commit=False)
        acct.owner = self.owner
        if commit:
            acct.save()
        return acct 
        
    class Meta:
        model = FixedTimeBankbookAccount
        #fields = ("name", "currency", "balance")
        exclude = ("owner", "state")

class DynamicForm(forms.ModelForm):
    """
    the form of user info
    """

    def __init__(self, user, *args, **kwargs):
        self.owner = user
        super(DynamicForm, self).__init__( *args, **kwargs)

    def save(self, commit=True):
        acct = super(DynamicForm, self).save(commit=False)
        acct.owner = self.owner
        if commit:
            acct.save()
        return acct 
        
    class Meta:
        model = CreditcardAccount 
        #fields = ("name", "currency", "balance")
        exclude = ("owner", "state")

class CreditCardForm(forms.ModelForm):
    """
    the form of user info
    """

    def save(self, commit=True):
        acct = super(CreditCardForm, self).save(commit=False)
        acct.owner = self.owner
        if commit:
            acct.save()
        return acct 
        
    def __init__(self, user, *args, **kwargs):
        self.owner = user
        super(CreditCardForm, self).__init__( *args, **kwargs)

    class Meta:
        model = CreditcardAccount 
        #fields = ("name", "currency", "balance")
        exclude = ("owner", "state")

class DebitCardForm(forms.ModelForm):
    """
    the form of user info
    """

    def __init__(self, user, *args, **kwargs):
        self.owner = user
        super(DebitCardForm, self).__init__( *args, **kwargs)

    def save(self, commit=True):
        acct = super(DebitCardForm, self).save(commit=False)
        acct.owner = self.owner
        if commit:
            acct.save()
        return acct 
        
    class Meta:
        model = DebitcardAccount 
        #fields = ("name", "currency", "balance")
        exclude = ("owner", "state")

class StockForm(forms.ModelForm):
    """
    the form of user info
    """

    def __init__(self, user, *args, **kwargs):
        self.owner = user
        super(StockForm, self).__init__( *args, **kwargs)

    def save(self, commit=True):
        acct = super(StockForm, self).save(commit=False)
        acct.owner = self.owner
        if commit:
            acct.save()
        return acct 
        
    class Meta:
        model = StockAccount 
        #fields = ("name", "currency", "balance")
        exclude = ("owner", "state")

class InsuranceForm(forms.ModelForm):
    """
    the form of user info
    """

    def __init__(self, user, *args, **kwargs):
        self.owner = user
        super(InsuranceForm, self).__init__( *args, **kwargs)

    def save(self, commit=True):
        acct = super(InsuranceForm, self).save(commit=False)
        acct.owner = self.owner
        if commit:
            acct.save()
        return acct 
        
    class Meta:
        model = InsuranceAccount 
        #fields = ("name", "currency", "balance")
        exclude = ("owner", "state")

class FundForm(forms.ModelForm):
    """
    the form of user info
    """

    def __init__(self, user, *args, **kwargs):
        self.owner = user
        super(FundForm, self).__init__( *args, **kwargs)

    def save(self, commit=True):
        acct = super(FundForm, self).save(commit=False)
        acct.owner = self.owner
        if commit:
            acct.save()
        return acct 
        
    class Meta:
        model = FundAccount 
        #fields = ("name", "currency", "balance")
        exclude = ("owner", "state")
